package com.example.myapplication3;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Activity自身作为监听器
        Button btnActivityListener = findViewById(R.id.btn_activity_listener);
        btnActivityListener.setOnClickListener(this);

        // 内部类监听器
        Button btnInnerClass = findViewById(R.id.btn_inner_class_listener);
        btnInnerClass.setOnClickListener(new InnerClickListener());

        // 外部类监听器
        Button btnExternal = findViewById(R.id.btn_external_listener);
        btnExternal.setOnClickListener(new ExternalClickListener(this));

        // XML绑定按钮（直接在XML中声明onClick属性）
        Button btnXmlBinding = findViewById(R.id.btn_xml_binding);
        btnXmlBinding.setOnClickListener(v -> onXmlBindingClick());

        // 跳转到系统信息界面
        Button btnSystemInfo = findViewById(R.id.btn_system_info);
        btnSystemInfo.setOnClickListener(v -> {
            Intent intent = new Intent(MainActivity.this, system_info.class);
            startActivity(intent);
        });

        // 跳转到进度条界面
        Button btnProgressDialog = findViewById(R.id.btn_progress_dialog);
        btnProgressDialog.setOnClickListener(v -> {
            Intent intent = new Intent(MainActivity.this, progress_dialog.class);
            startActivity(intent);
        });
    }

    // Activity自身作为监听器的实现
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_activity_listener) {
            Toast.makeText(this, "Activity监听器触发", Toast.LENGTH_SHORT).show();
        }
    }

    // XML绑定的点击方法
    public void onXmlBindingClick() {
        Toast.makeText(this, "XML绑定点击触发", Toast.LENGTH_SHORT).show();
    }

    // 内部类监听器
    private class InnerClickListener implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            Toast.makeText(MainActivity.this, "内部类监听器触发", Toast.LENGTH_SHORT).show();
        }
    }
}